package hzst.android.form.view;

import hzst.android.form.info.EditViewInfo;
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.LinearLayout;

public class FMEditText extends FMBaseView{
	private EditText view;
	
	public FMEditText(Context context) {
		super(context);
	}

	@Override
	protected void initView() {
		
	}
	
	@Override
	public void showView() {
		view = new EditText(context);
		String value = info.getSubmitValues().get(0).getValue();//EditText只有一个value
		EditViewInfo.setInputType((EditText) view, ((EditViewInfo)info).getIntputType());
		((EditText) view).setText(value);
		if(info.isReadOnly()){
			view.setEnabled(false);
		}
		((EditText) view).addTextChangedListener(new TextWatcher() {
			
			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {}
			
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {}
			
			@Override
			public void afterTextChanged(Editable s) {
				viewCreator.setSubmitValue(s.toString(), info);
//				viewCreator.updateViewInfo(info, true);
			}
		});
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
		view.setLayoutParams(params);
		setLayoutParams(params);
		addView(view);
	}
	
	@Override
	public void setContent(CharSequence content) {
		view.setText(content);
	}

}
